package com.qf.controller;


import com.qf.service.GoodsService;
import com.qf.service.impl.GoodsServiceImpl;
import org.springframework.web.bind.annotation.*;

/**
 * @program: front_system
 * @description:
 * @author: Mr.Wu
 * @create: 2020-07-03 10:55
 **/


@CrossOrigin("*")
@RestController
@RequestMapping("/good")
public class GoodsController {

    private GoodsServiceImpl goodsService;

    public GoodsController(GoodsServiceImpl goodsService) {
        this.goodsService = goodsService;

    }

    @PostMapping("/all")
    public Object show(){
        return goodsService.getShow();
    }

    @PostMapping("/ids")
    public Object ids(String ids){
        String[] idsArr = ids.split(","); //将前端出入过来的ids拆分为数组, 1001,1002,1003
        Integer[] idsInt = new Integer[idsArr.length]; //生成长度和字符串数组长度一样的整数数组
        for(int i = 0; i < idsArr.length; i++) {
            idsInt[i] = Integer.parseInt(idsArr[i]);
        }
        return goodsService.getGoodsByIds(idsInt);
    }
}
